﻿using Castle.DynamicProxy;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace UL.Interceptors
{
    public class Inters : IInterceptor
    {
        private readonly ILogger<Inters> loggers;

        public Inters(ILogger<Inters> logger)
        {
            loggers = logger;
        }

        public void Intercept(IInvocation invocation)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            invocation.Proceed();
            sw.Stop();
            string actionName = invocation.Method.Name; 
            string className = invocation.TargetType.Name;
            loggers.LogInformation($"执行了{className}的{actionName}方法，用时 {sw.ElapsedMilliseconds}毫秒\n,执行结果是{invocation.ReturnValue}");
        }
    }
}
